<?php

namespace App\Dao;

use App\Model\User;
use App\Model\UserBlacklist;
use App\Utils\FunUtil;
use App\Utils\LoggerUtil;
use App\Utils\MemcacheClient;
use App\Utils\RedisClient;
use Hyperf\Context\ApplicationContext;
use Hyperf\DbConnection\Db;
use function Hyperf\Translation\trans;

class IndexActionDao
{
    private static $instance;

    public static function getInstance()
    {
        if (!self::$instance) {
            self::$instance = Applicationcontext::getcontainer()->get(self::class);
        }
        return self::$instance;
    }

    public function deleteInitCache($userInfo)
    {
        MemcacheClient::getInstance()->delete('robot_audio_times_flag_' . $userInfo['id']);
        MemcacheClient::getInstance()->delete("robot_msg_times_" . $userInfo['id']);
        MemcacheClient::getInstance()->delete("robot_pre_content_type_2_" . $userInfo['id']);
    }

    /**
     * Note - 首页空闲用户列表
     * DateTime 2024/7/19 11:44
     * User Admin
     * @param $type
     * @param $user
     * @param $page
     * @param $pageSize
     * @return array
     */
    public function idleUserList($language, $type = 1, $user = array(), $page = 1, $pageSize = 10)
    {
        $userModel = UserDao::getInstance();
        $userIds = $userModel->selectConditionUserList($type, $user['id'], 1, $page, $pageSize);

        $onlineUids['man'] = $userModel->getOnlineUids(1);
        $onlineUids['woman'] = $userModel->getOnlineUids(2);
        //在线用户ID
        $onlineUid = $user['sex'] == 2 ? $onlineUids['man'] : $onlineUids['woman'];

        $memcache = MemcacheClient::getInstance();
        $calling_uids_cache = $memcache->get("calling_uids");
        if ($calling_uids_cache === false) {
            // 获取视频中的用户ID
            $calling_uids = PayCallDao::getInstance()->getCallingUsers();
            $memcache->set("calling_uids", $calling_uids, 5);
        } else {
            $calling_uids = (array)$calling_uids_cache;
        }

        // 获取在线用户
        $tmpUserIds = array_map(function ($v) use ($onlineUid, $calling_uids) {
            // 用户不在线或者 开启勿扰模式
            if (!in_array($v['id'], $onlineUid) || $v['is_disturb'] == 1) {
                $v['online'] = 0;
                $v['sort'] = 0;
            } else {
                // 用户在线
                if (in_array($v['id'], $calling_uids)) {
                    $v['online'] = 2;
                    $v['sort'] = 2;
                } else {
                    $v['online'] = 1;
                    $v['sort'] = 3;
                }
            }
            return $v;
        }, $userIds);

        $sort1 = array_column($tmpUserIds, 'click_time');
        array_multisort($sort1, SORT_DESC, $tmpUserIds);

        $userIds = array_column($tmpUserIds, 'id');
        $userList = [];
        if (!empty($userIds)) {
            $anchor_cashes = $userModel->loadAnchors($userIds);
            $anchorVideo = AnchorVideoDao::getInstance()->loadAnchorsVideo($userIds);
            $anchorRemarks = UserRemarkDao::getInstance()->getOne($user['id']);

            foreach ($userIds as $v) {
                if (sizeof($anchor_cashes) > 0 && isset($anchor_cashes[$v])) {
                    $tmp = $anchor_cashes[$v];
                    $tmp['remarks_name'] = !empty($anchorRemarks[$v]) ? $anchorRemarks[$v]['remarks_name'] : '';
                } else {
                    $tmp = $userModel->getUserListInfo($language, $v);
                }
                if (empty($tmp)) continue;
                $tmp['video'] = isset($anchorVideo[$v]) ? $anchorVideo[$v]['url'] : '';

                $tmp['click_time'] = $tmp['click_time'] ?: $tmp['login_time'];

                $tmp['vip'] = $tmp['super_noble'] == 1 ? 2 : ($tmp['noble'] == 1 ? 1 : 0);

                if (!in_array($tmp['id'], $onlineUid) || $tmp['is_disturb'] == 1) {
                    $tmp['online'] = 0;
                } else {
                    if (in_array($tmp['id'], $calling_uids)) {
                        $tmp['online'] = 2;
                    } else {
                        $tmp['online'] = 1;
                    }
                }
                $userList[] = $tmp;
            }
        }
        return $userList;
    }


    /**
     * 首页推荐用户列表
     * @param $type
     * @param $uid
     * @param int $sex
     * @param int $gift_count
     * @param int $page
     * @param int $pageSize
     * @param bool $isRand
     * @param int $online
     * @param array $filter
     * @param string $province
     * @return array|false
     */
    public function recommendUserList($version_code, $language, $type, $uid, $sex = 1, $gift_count = 0, $page = 1, $pageSize = 10, $isRand = false, $online = 0, $filter = [], $province = '')
    {
        $redis = RedisClient::getInstance();
        $redis->select(14);

        // 记录用户上次刷新时间
        if ($page == 1) {
            $redis->hSet("user_index_flag_time", "uid_" . $uid, time());
        }

        if ($sex == 1) {
            // 男性查看女性
            $rs = $this->recommendUserWoman($redis, $type, $uid, $page, $pageSize, $isRand, $filter, $province, $language, $online);
        } else {
            // 女性查看男用户
            $rs = $this->recommendUserMan($redis, $type, $uid, $page, $pageSize, $isRand, $filter, $province, $language, $online, $version_code);
        }
        // $signArr = trans('slogan', [], $language);
        foreach ($rs as &$vo) {
            $vo['ext'] = json_decode($vo['ext'], true);
            $vo['job'] = !empty($vo['ext']['job']) && (string)$vo['ext']['job'] != "null"  ? trans('information.job', [], $language)[$vo['ext']['job']]['name'] : '';
            $vo['weight'] = !empty($vo['ext']['weight']) && (string)$vo['ext']['weight'] != "" ? $vo['ext']['weight'] : '60';
            $vo['constellation'] = isset($vo['ext']['constellation']) && (string)$vo['ext']['constellation'] != "" ? trans('constellation.' . $vo['ext']['constellation'], [], $language) : '';
            $vo['list_type'] = 0;
            $vo['audio_time'] = 0;
            $vo['pay_call_ranking'] = 0;
            $vo['bust'] = isset($vo['ext']['bust']) && (string)$vo['ext']['bust'] != "" ? $vo['ext']['bust'] : 'C';
            $vo['head_image'] = FunUtil::formatHeadImg($vo['head_image']);
            $vo['audio_greeting_url'] = strval($vo['audio_greeting_url'] ?? '');
            $vo['evaluate_color'] = strval($vo['evaluate_color'] ?? '');

            // if (empty($vo['signature'])) {
            //     $vo['signature'] = $signArr[array_rand($signArr)];
            // } else {
            //     $vo['signature'] = strval($vo['signature']);
            // }

            $vo['is_new_user'] = 0;
            if ($vo['register_time'] + 7 * 86400 >= time()) {
                $vo['is_new_user'] = 1;
            }

            $vo['online'] = intval($vo['online']);
            $vo['star_rank'] = empty($vo['star_rank']) ? 1 : intval($vo['star_rank']);
            $vo['vip'] = $vo['super_noble'] == 1 ? 2 : ($vo['noble'] == 1 ? 1 : 0);
            $vo['click_time'] = $vo['click_time'] ?: $vo['login_time'];
            unset($vo['ext']);
            unset($vo['total']);
        }
        return $rs;
    }


    /**
     * Note - 推荐给你的女用户
     * DateTime 2024/7/19 16:37
     * User Admin
     * @param $redis
     * @param $type
     * @param $uid
     * @param $page
     * @param $pageSize
     * @param $isRand
     * @param $filter
     * @param $province
     * @param $language
     * @param $online
     * @return mixed[]
     */
    public function recommendUserWoman($redis, $type, $uid, $page, $pageSize, $isRand, $filter, $province, $language, $online)
    {
        $womanField = [
            "u.id",
            "u.nickname",
            "u.head_image",
            "u.sex",
            "u.ext",
            "u.height",
            "a.audio_greeting_url",
            "u.signature",
            "a.star_rank",
            "a.video_price",
            "a.evaluate",
            "a.evaluate_color",
            "u.age",
            "u.vip",
            "u.province",
            "u.city",
            "u.user_type",
            "u.level",
            "u.is_disturb",
            "u.noble",
            "u.super_noble",
            "u.login_time",
            "u.click_time",
            "u.is_faceAuth",
            "u.is_cardAuth",
            "a.force_vip",
            "a.is_insideS",
            "u.register_time",
            "u.hide_call_status",
            "u.channel",
            DB::raw("JSON_UNQUOTE(JSON_EXTRACT(u.ext2, '$.channel')) as ext_channel"),
        ];
        $womanField[] = DB::raw("CASE WHEN is_disturb = 1 AND online > 0 THEN 4 ELSE online END as online");
        $womanField[] = DB::raw("CASE WHEN online = 1 THEN 3 ELSE online END as onlines");

        $hour = date("H");
        $womanField[] = ($hour > 8 && $hour <= 20)
            ? DB::raw('a.score_origin + a.score_sort as total')
            : DB::raw('a.score_origin_2 + a.score_sort as total');
        // 初始化查询
        // $query = DB::table('tb_user as u')
        $query = User::query()->from('tb_user as u')
            ->leftJoin('tb_anchor as a', function ($join) {
                $join->on('a.uid', '=', 'u.id')
                    ->where('a.status', 0);
            })
            ->where('u.sex', 2)
            ->where('u.click_time', '>=', strtotime("-30 days"))
            ->where('u.nickname', '!=', DB::raw('id'))
            ->where('u.login_env', 0)
            ->where('u.is_audit', 0)
            ->where('u.in_audit', 0)
            ->where('u.isdel', 0)
            ->where('u.status', 0)
            ->where('u.not_show', 0);
        if ($type == 1) {
            if (!empty($filter)) {
                $query = $this->filterCondition($filter, $query, $language);
            } else {
                $pageSize = 40;
                // 首页推荐
                $poolA = $redis->get('index_woman_list_poolA');
                $poolB = $redis->get('index_woman_list_poolB');
                $poolC = $redis->get('index_woman_list_poolC');
                $firstUsers = [];
                if (!empty($poolA)) {
                    $poolA = explode(",", $poolA);
                    shuffle($poolA);
                    $firstUsers = array_merge($firstUsers, array_slice($poolA, 0, 10));
                }
                if (!empty($poolB)) {
                    $poolB = explode(",", $poolB);
                    shuffle($poolB);
                    $firstUsers = array_merge($firstUsers, array_slice($poolB, 0, 6));
                }
                if (!empty($poolC)) {
                    $poolC = explode(",", $poolC);
                    shuffle($poolC);
                    $firstUsers = array_merge($firstUsers, array_slice($poolC, 0, 4));
                }

                if (!empty($firstUsers)) {
                    $firstUid = implode(",", $firstUsers);

                    // $field[] = "case when online=1 and u.id in ({$firstUid}) then 0 when online=1 and province='{$province}' and u.push_level>0 then 1 when online=1 and  province!='{$province}' and u.push_level>0 then 2 when online=2 then 3 else 4 end sort_level";
                    $womanField[] = DB::raw("CASE 
                                    WHEN online = 1 AND u.id IN ({$firstUid}) THEN 0
                                    WHEN online = 1 AND province = '{$province}' AND u.push_level > 0 THEN 1
                                    WHEN online = 1 AND province != '{$province}' AND u.push_level > 0 THEN 2
                                    WHEN online = 2 THEN 3
                                    ELSE 4
                                END as sort_level");
                } else {
                    // $field[] = "case when online=1 and province='{$province}' and u.push_level>0 then 1 when online=1 and  province!='{$province}' and u.push_level>0 then 2 when online=2 then 3 else 4 end sort_level";
                    $womanField[] = DB::raw("CASE 
                                    WHEN online = 1 AND province = '{$province}' AND u.push_level > 0 THEN 1
                                    WHEN online = 1 AND province != '{$province}' AND u.push_level > 0 THEN 2
                                    WHEN online = 2 THEN 3
                                    ELSE 4
                                END as sort_level");
                }

                // $orderBy = "sort_level asc,rand(),login_time desc";
                $query->orderByRaw("sort_level ASC, RAND(), login_time DESC");

            }
        }

        // 查询用户黑名单
        $blackList = UserBlacklistDao::getInstance()->getBlacklist($uid);
        // $black_list = array_column($black_list, 'black_uid');
        if (!empty($black_list)) {
            // $black_list = implode(",", $black_list);
            // $where .= " AND u.id not in ({$black_list})";
            $blackListIds = implode(',', array_column($blackList, 'black_uid'));
            $query->whereNotIn('u.id', $blackListIds);
        }

        if ($online == 1) {
            // $where .= " AND online>0";
            $query->where('online', '>', 0);
        }

        // $limit = ' LIMIT ' . ($page - 1) * $pageSize . ",{$pageSize}";
        if ($isRand) {
            // $limit = ' LIMIT ' . "{$pageSize}";
            // $orderBy = "onlines desc,is_disturb asc,RAND()";
            // 设置排序
            $query->orderByRaw("onlines DESC,is_disturb ASC,RAND()");
        }
        $offset = ($page - 1) * $pageSize;
        $query->skip($offset)->take($pageSize);
        return $query->select($womanField)->get()->toArray();

        // $profit = " ";
        // $sql = "SELECT {$field} FROM tb_user u LEFT JOIN tb_anchor a ON a.uid=u.id and a.status=0 WHERE u.sex = 2 and click_time>={$click_time} AND nickname!=id and  u.login_env=0 and u.is_audit = 0 and u.in_audit = 0 and u.isdel = 0 AND u.`status` = 0 AND u.`not_show` = 0 $profit {$where} ORDER BY {$orderBy} {$limit}";
        // LoggerUtil::write('index_recommend_woman_sql', $sql, 'man');
        // return modelToArray($rs);


    }


    /**
     * Note - 推荐给你的男用户
     * DateTime 2024/7/19 16:01
     * User Admin
     * @param $redis
     * @param $type
     * @param $uid
     * @param $page
     * @param $pageSize
     * @param $isRand
     * @param $filter
     * @param $province
     * @param $language
     * @param $online
     * @param $version_code
     * @return mixed[]
     */
    public function recommendUserMan($redis, $type, $uid, $page, $pageSize, $isRand, $filter, $province, $language, $online, $version_code)
    {
        $userField = [
            "id",
            "nickname",
            "head_image",
            "sex",
            "ext",
            "height",
            "signature",
            "age",
            "vip",
            "province",
            "city",
            "user_type",
            "level",
            "is_disturb",
            "noble",
            "super_noble",
            "login_time",
            "click_time",
            "is_faceAuth",
            "is_cardAuth",
            "register_time",
            "hide_call_status",
            "channel",
            DB::raw("JSON_UNQUOTE(JSON_EXTRACT(ext2, '$.channel')) as ext_channel"),
        ];

        $online_flag = ($version_code >= 116) ? 4 : 2;
        // $userField[] = "case when is_disturb=1 and `online`>0 then $online_flag else `online` end as `online`";
        $userField[] = DB::raw("CASE WHEN is_disturb = 1 AND online > 0 THEN $online_flag ELSE online END as online");

        // $where = " ";

        // $userField[] = "case when online=1 and is_disturb=0 and province='{$province}' then 0 when online=1 and is_disturb=0 and province!='{$province}' then 1 when online=2 and  province='{$province}' then 2 when online=2 and province!='{$province}' then 3 when online=1 and is_disturb=1 then 4 else 5 end sort_level";
        $userField[] = DB::raw("CASE WHEN online = 1 AND is_disturb = 0 AND province = '{$province}' THEN 0 WHEN online = 1 AND is_disturb = 0 AND province != '{$province}' THEN 1 WHEN online = 2 AND province = '{$province}' THEN 2 WHEN online = 2 AND province != '{$province}' THEN 3 WHEN online = 1 AND is_disturb = 1 THEN 4 ELSE 5 END as sort_level");

        // $query = DB::table('tb_user as u')
        //     ->leftJoin('tb_anchor as a', function ($join) {
        //         $join->on('a.uid', '=', 'u.id')->where('a.status', 0);
        //     });
        $query = User::query()->from('tb_user as u')->where('nickname', '!=', DB::raw('id'))
            ->where('login_env', 0)
            ->where('is_audit', 0)
            ->where('in_audit', 0)
            ->where('isdel', 0)
            ->where('status', 0)
            ->where('sex', 1)
            ->where('not_show', 0)
            ->where('click_time', '>=', strtotime("-30 days"));


        if ($type == 1) {
            // 高级筛选
            if (!empty($filter)) {
                $query = $this->filterCondition($filter, $query, $language);
            } else {
                // 上次刷新时间
                $lastRefreshTime = $redis->hget('user_index_flag_time', 'uid_' . $uid);
                if ($page != 1 && !empty($lastRefreshTime)) {
                    // $where .= " and register_time <= $lastRefreshTime";
                    $query->where('register_time', '<=', $lastRefreshTime);
                }

            }
        }

        // 查询用户黑名单
        $blackList = UserBlacklistDao::getInstance()->getBlacklist($uid);
        if (!empty($blackList)) {
            // $black_list = implode(",", $black_list);
            // $where .= " AND u.id not in ({$black_list})";
            // $black_list = array_column($black_list, 'black_uid');
            $blackListIds = implode(',', array_column($blackList, 'black_uid'));
            $query->whereNotIn('u.id', $blackListIds);
        }


        if ($online == 1) {
            // $where .= " AND online>0";
            $query->where('online', '>', 0);
        }


        $orderBy = "sort_level asc,rand()";
        if ($isRand) {
            $orderBy = "rand(),login_time DESC";
        }
        $query->orderByRaw($orderBy);

        $offset = ($page - 1) * $pageSize;
        $query->skip($offset)->take($pageSize);
        // 执行查询
        return $query->select($userField)->get()->toArray();


    }


    /**
     * Note - 拼装过滤条件
     * DateTime 2024/7/19 16:00
     * User Admin
     * @param $filter
     * @param $query
     * @param $language
     * @return mixed
     */
    private function filterCondition($filter, $query, $language)
    {
        // 高级筛选
        // 所在地
        if (isset($filter['location']) && $filter['location'] != "") {
            $loca = explode("-", $filter['location']);
            if ($loca[0] && $loca[0] != '') {
                // $province = mb_substr($loca[0], 0, mb_strlen($loca[0]) - 1);
                // $where .= " and u.province = '{$province}'";
                // $query->where('u.province', $province);
                $country = $loca[0];
                $query->where('u.country', $country);
            }

            if ($loca[1] && $loca[1] != '') {
                // $city = mb_substr($loca[1], 0, mb_strlen($loca[1]) - 1);
                // $where .= " and u.city = '{$city}'";
                $city = $loca[1];
                $query->where('u.province', $city);
            }
        }

        // 年龄
        if (isset($filter['age']) && $filter['age'] != "") {
            list($minAge, $maxAge) = explode("~", $filter['age']);
            if ($minAge && $maxAge != '') {
                // $age = mb_substr($ages[0], 0, mb_strlen($ages[0]) - 1);
                // $where .= " and u.age>=$age";
                $minAge = mb_substr($minAge, 0, mb_strlen($minAge) - 1);
                $query->where('u.age', '>=', $minAge);
            }
            // if ($ages[1] && $ages[1] != '') {
            //     $age = mb_substr($ages[1], 0, mb_strlen($ages[1]) - 1);
            //     $where .= " and u.age<=$age";
            // }
            if ($maxAge && $maxAge != '') {
                $maxAge = mb_substr($maxAge, 0, mb_strlen($maxAge) - 1);
                $query->where('u.age', '<=', $maxAge);
            }
        }

        // 身高
        if (isset($filter['height']) && $filter['height'] != "") {
            // $heights = explode("~", $filter['height']);
            // if ($heights[0] && $heights[0] != '不限') {
            //     $height = substr($heights[0], 0, strlen($heights[0]) - 2);
            //     $where .= " and u.height>=$height";
            // }
            // if ($heights[1] && $heights[1] != '不限') {
            //     $height = substr($heights[1], 0, strlen($heights[1]) - 2);
            //     $where .= " and u.height<=$height";
            // }
            list($minHeight, $maxHeight) = explode("~", $filter['height']);
            if ($minHeight && $minHeight != '') {
                $minHeight = substr($minHeight, 0, strlen($minHeight) - 2);
                $query->where('u.height', '>=', $minHeight);
            }

            if ($maxHeight && $maxHeight != '') {
                $maxHeight = substr($maxHeight, 0, strlen($maxHeight) - 2);
                $query->where('u.height', '<=', $maxHeight);
            }
        }

        // 体重
        if (isset($filter['weight']) && $filter['weight'] != "") {
            // $weights = explode("~", $filter['weight']);
            // if ($weights[0] && $weights[0] != '不限') {
            //     $weight = substr($weights[0], 0, strlen($weights[0]) - 2);
            //     $where .= " and u.weight>=$weight";
            // }
            // if ($weights[1] && $weights[1] != '不限') {
            //     $weight = substr($weights[1], 0, strlen($weights[1]) - 2);
            //     $where .= " and u.weight<=$weight";
            // }
            list($minWeight, $maxWeight) = explode("~", $filter['weight']);
            if ($minWeight && $minWeight != '') {
                $minWeight = substr($minWeight, 0, strlen($minWeight) - 2);
                $query->where('u.weight', '>=', $minWeight);
            }

            if ($maxWeight && $maxWeight != '') {
                $maxWeight = substr($maxWeight, 0, strlen($maxWeight) - 2);
                $query->where('u.weight', '<=', $maxWeight);
            }
        }

        // 学历
        if (isset($filter['education']) && $filter['education'] != "") {
            // $edus = array_column(trans('information.education', [], $language), 'value', 'name');
            // if (isset($edus[$filter['education']])) {
            //     $where .= " and u.ext<>'' and JSON_EXTRACT(u.ext, '$.education')='{$edus[$filter['education']]}'";
            // }
            $edus = array_column(trans('information.education', [], 'zh-cn'), 'name', 'value');
            if (isset($edus[$filter['education']])) {
                $query->where(function ($q) use ($filter) {
                    $q->where('u.ext', '!=', '')
                        ->where(DB::raw('JSON_EXTRACT(u.ext, \'$.education\')'), $filter['education']);
                });
            }
        }
        return $query;
    }


    /**
     * 获取首页用户列表 - 搜索
     * @param $usex - 查询用户的性别 1男 2女
     * @param $keyword
     * @param int $page
     * @param $params
     * @return array
     */
    public function SearchUserListPage($usex, $keyword, int $page, $params)
    {
        // 男用户只能查询女用户
        if ($usex == 1) {
            $sex = 2;
        } else {
            // 女用户只能查询男用户
            $sex = 1;
        }
        $is_audit = (new AppUpgradeDao())->isHideCall($params['from'], $params['version_code'], $params['channel']);

        if ($is_audit) {
            $where = " in_audit = 1";
        } else {
            if ($usex == 1) {
                $where = "in_audit = 0 and is_audit=0 and login_env=0 ";
            } else {
                $where = '';
            }

        }
        $field = [
            "u.id",
            "u.nickname",
            "u.head_image",
            "u.sex",
            "u.ext",
            "u.height",
            "a.audio_greeting_url",
            "u.signature",
            "a.star_rank",
            "a.evaluate",
            "a.evaluate_color",
            "u.age",
            "u.vip",
            "u.province",
            "u.city",
            Db::raw("case when is_disturb=1 and online>0 then 4 else online end as online"),
            "u.user_type",
            "u.level",
            "u.is_disturb",
            "u.noble",
            "u.super_noble",
            "u.login_time",
            "u.click_time",
            "a.force_vip",
            "a.is_insideS",
            "u.hide_call_status",
            "u.show_wealth",
        ];
        $offset = ($page - 1) * 20;
        // $sql = "select {$field}  from {$this->table} u force index(idx_promo) left join tb_anchor a on u.id=a.uid where sex=" . ($sex == 1 ? 2 : 1) . " and isdel=0 {$where} and (a.status=0 or isnull(a.status)) and (id like '%" . $keyword . "%' or `nickname` like '%" . $keyword . "%') order by id DESC {$limit}";
        return User::query()->from('tb_user AS u')->leftJoin('tb_anchor AS a', 'u.id', '=', 'a.uid')
            ->select($field)
            ->where('sex', $sex)
            ->where('isdel', 0)
            ->when(!empty($where), function ($query) use ($where) {
                $query->whereRaw($where);
            })
            ->where(function ($query) use ($where) {
                $query->where('a.status', 0)
                    ->orWhereNull('a.status');
            })
            ->where(function ($query) use ($keyword) {
                $query->where('id', 'like', '%' . $keyword . '%')
                    ->orWhere('nickname', 'like', '%' . $keyword . '%');
            })
            ->orderBy('id', 'desc')
            ->offset($offset)
            ->limit(20)
            ->get()->toArray();

        // try {
        //     $pd = $this->createCommand($sql);
        //     $pd->execute();
        //     $rs = $pd->fetchAll(PDO::FETCH_ASSOC);
        //     $pd->closeCursor();
        // } catch (PDOException $e) {
        //     Tool::JSON(\CodeData::NO_PROMPT, '-1', 'database error');
        // }
        // return $rs ?: [];
    }


}